//
//  HomeListTableViewCell.m
//  PreschoolEducation
//
//  Created by 传铎 on 2020/11/9.
//  Copyright © 2020 李传铎. All rights reserved.
//

#import "HomeListTableViewCell.h"

#define kHeight [UIScreen mainScreen].bounds.size.height - __kNavigationBarHeight__ - 46 - __kTabBarHeight__

@interface HomeListTableViewCell ()<UIScrollViewDelegate>

@property (nonatomic, strong) UIScrollView *scrollView;


@end
@implementation HomeListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.contentView addSubview:self.scrollView];
        
        [self CreatUI];
    }
    return self;
}

- (void)CreatUI{
    
    
self.oneVC = [[OrderViewController alloc]init];
   self.twoVC = [[InformationViewController alloc]init];
 
   

   self.oneVC.view.frame = CGRectMake([UIScreen mainScreen].bounds.size.width * 0, 0, [UIScreen mainScreen].bounds.size.width, kHeight);
   self.twoVC.view.frame = CGRectMake([UIScreen mainScreen].bounds.size.width *1, 0, [UIScreen mainScreen].bounds.size.width, kHeight);

   [self.scrollView addSubview:self.oneVC.view];
   [self.scrollView addSubview:self.twoVC.view];
    
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    // 为了横向滑动的时候，外层的tableView不动
    if (!self.isSelectIndex) {
        if (scrollView == self.scrollView) {
            if (self.delegate &&
                [self.delegate respondsToSelector:@selector(mmtdOptionalScrollViewDidScroll:)]) {
                [self.delegate mmtdOptionalScrollViewDidScroll:scrollView];
            }
        }
    }
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    self.isSelectIndex = NO;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    if (scrollView == self.scrollView) {
        if (self.delegate &&
            [self.delegate respondsToSelector:@selector(mmtdOptionalScrollViewDidEndDecelerating:)]) {
            [self.delegate mmtdOptionalScrollViewDidEndDecelerating:scrollView];
        }
    }
}

#pragma mark - Init Views

- (UIScrollView *)scrollView {
    if (!_scrollView) {
        NSInteger count = 2;

        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, kHeight)];
        _scrollView.delegate = self;
        _scrollView.pagingEnabled = YES;
        _scrollView.scrollEnabled = NO;
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.contentSize = CGSizeMake(_scrollView.frame.size.width * count, _scrollView.frame.size.height);
    }
    return _scrollView;
}

- (void)setObjectCanScroll:(BOOL)objectCanScroll {
    _objectCanScroll = objectCanScroll;
    self.oneVC.vcCanScroll = objectCanScroll;
    self.twoVC.vcCanScroll = objectCanScroll;

    if (!objectCanScroll) {
        
        [self.oneVC.tableView setContentOffset:CGPointZero animated:NO];
        [self.twoVC.tableView setContentOffset:CGPointZero animated:NO];
      
    }
}


@end
